package cn.tedu.nio.channel;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;

public class Client {
    public static void main(String[] args) {
        try {
            SocketChannel sc = SocketChannel.open();
            // 设置为非阻塞
            sc.configureBlocking(false);
            sc.connect(new InetSocketAddress("localhost", 8090));
            while (!sc.isConnected()) {
                sc.finishConnect();
            }
            ByteBuffer buffer = ByteBuffer.wrap("Hello server".getBytes());
            sc.write(buffer);
            sc.close();
        } catch (IOException ioException) {
            ioException.printStackTrace();
        }
    }
}
